import { getPrincipalsUserList } from '/@/api/demo/system';
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { checkID } from '/@/utils/index';
import debounce from 'lodash.debounce';
import { TreeSelect } from 'ant-design-vue';
const { SHOW_PARENT, SHOW_ALL, SHOW_CHILD } = TreeSelect;
import { useUserStore } from '/@/store/modules/user';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { encryptByMd5, strongPwdRegex } from '/@/utils/cipher';

export const columns: BasicColumn[] = [
  {
    title: '单位名称',
    dataIndex: 'name',
  },
  {
    title: '单位负责人',
    dataIndex: 'principalsName',
  },
  {
    title: '创建时间',
    dataIndex: 'modifiedOn',
    width: 200,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '单位名称',
    component: 'Input',
    labelWidth: '6em',
    colProps: { span: 8 },
  },
  {
    field: 'principalsName',
    label: '负责人',
    component: 'Input',
    labelWidth: '6em',
    colProps: { span: 8 },
  },
];

export const accountPwdFormSchema: FormSchema[] = [
  {
    field: 'pwd',
    label: '密码',
    defaultValue: '',
    component: 'InputPassword',
    rules: [
      {
        required: true,
        message: '请输入新密码',
      },
      {
        pattern: strongPwdRegex,
        // message: '密码必须为八位及以上并且大小写字母数字特殊字符三项都要包括',
        message: '密码中必须包含字母、数字、特殊字符，(长度在 8-30位)！',
      },
    ],
  },
];

export function accountFormSchema(roleType): FormSchema[] {
  const addUnit: FormSchema[] = [
    {
      field: 'name',
      label: '单位名称',
      defaultValue: '',
      component: 'Input',
      rules: [
        {
          required: true,
          message: '请输入单位名称',
        },
      ],
    },
    {
      label: '单位负责人',
      field: 'principals',
      component: 'ApiSelect',
      componentProps: {
        api: () => getPrincipalsUserList(roleType),
        labelField: 'nickname',
        valueField: 'number',
        valueFieldFunc: (rcd) => `${rcd['uname']} (${rcd['nickname']})`,
      },
      required: true,
    },
  ];

  return addUnit;
}

export const addMngerFormSchema: FormSchema[] = [
  {
    label: '单位负责人',
    field: 'principals',
    component: 'ApiSelect',
    componentProps: {
      api: getPrincipalsUserList,
      labelField: 'nickname',
      valueField: 'number',
      valueFieldFunc: (rcd) => `${rcd['uname']} (${rcd['nickname']})`,
      modeRef: 'multiple',
    },
    required: true,
  },
];
